﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.UnifyShow.Business;
using Oracle.DataAccess.Client;
using System.Data;

namespace Wicresoft.UnifyShow.BusinessImpl
{
    public class ServiceDesk : Basic, IServiceDesk
    {
        //事件来源
        public List<IncidentAndChangeModel> IncidentSourceBySite(int? site, int? bnid, DateTime? sTime, DateTime? eTime)
        {
            List<OracleParameter> cmdParms = new List<OracleParameter>();
            string sqlStr = "select Count(*) alls,Source ID from Incident where 1=1";
            if (site != null)
            {
                sqlStr += " and siteid=:site";
                cmdParms.Add(new OracleParameter("site", OracleDbType.Int32, site, ParameterDirection.Input));
            }
            if (bnid != null)
            {
                sqlStr += " and BusinessSystemId = :bnid";
                cmdParms.Add(new OracleParameter("bnid", OracleDbType.Int32, bnid, ParameterDirection.Input));
            }
            if (sTime != null)
            {
                sqlStr += " and TicketCreateTime >= :sTime";
                cmdParms.Add(new OracleParameter("sTime", OracleDbType.Date, sTime, ParameterDirection.Input));
            }
            if (eTime != null)
            {
                sqlStr += " and TicketCreateTime <= :eTime";
                cmdParms.Add(new OracleParameter("eTime", OracleDbType.Date, eTime, ParameterDirection.Input));
            }
            sqlStr += " group by Source";
            OracleDataReader dr = oda.ExecuteReader(sqlStr, cmdParms);
            return ModelHelper<IncidentAndChangeModel>.GetModel_By_OracleDataReader(dr);
        }

        //服务台事件解决率
        public decimal GetApproveCountIncidentbyResolvedGroup(int? site, int? bnid, DateTime? sTime, DateTime? eTime)
        {
            List<OracleParameter> cmdParms = new List<OracleParameter>();
            string sqlStr = "select Count(*) from Incident where status >= 4 and ResolvedGroup =0";
            if (site != null)
            {
                sqlStr += " and siteid=:siteid";
                cmdParms.Add(new OracleParameter("siteid", OracleDbType.Int32, site, ParameterDirection.Input));
            }
            if (bnid != null)
            {
                sqlStr += " and BusinessSystemId = :bnid";
                cmdParms.Add(new OracleParameter("bnid", OracleDbType.Int32, bnid, ParameterDirection.Input));
            }
            if (sTime != null)
            {
                sqlStr += " and TicketCreateTime >= :sTime";
                cmdParms.Add(new OracleParameter("sTime", OracleDbType.Date, sTime, ParameterDirection.Input));
            }
            if (eTime != null)
            {
                sqlStr += " and TicketCreateTime <= :eTime";
                cmdParms.Add(new OracleParameter("eTime", OracleDbType.Date, eTime, ParameterDirection.Input));
            }
            return ModelHelper<IncidentModel>.GetModelCount_By_DirectSql(sqlStr, cmdParms, oda);
        }
    }
}
